// xc_lshop/shop/order/com/orderinforbottom.js
var actbill = require('../../model/order_bill')
var actcart = require('../../../../xc/sys/cart')

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    themconfig: Object,
    refundconfig: Object
  },

  /**
   * 组件的初始数据
   */
  data: {
    xcmodel: null,
    loading: false,
  },

  /**
   * 组件的方法列表
   */
  methods: {
    set(obj) {
      this.setData({
        xcmodel: obj
      })
    },
    opload(ishow, tiptext) {
      var selectcomponent = this.selectComponent("#opwebtool");
      if (ishow) {
        selectcomponent.showmodel(tiptext)
      } else {
        selectcomponent.closemodel(tiptext)
      } //opwebtool
    },
    optool(ev) {
      var op = ev.target.dataset.op
      var dataset = ev.currentTarget.dataset
      var item = dataset.item
      console.log(op)
      console.log(item)

      var that = this;
      switch (op) {
        case "wuliinfo":{
          wx.navigateToMiniProgram({
            appId: 'wx6885acbedba59c14',
            path:"pages/result/result?nu="+item.expressnum+"&querysource=third_xcx"
          })
          break;
        }
        case "buyagain": {
          if(item.ordertype=='9'){
            wx.navigateTo({
              url: '/xc_lshop/savemoney/recharge/hc/infor?gid='+item.orderinfo.g_id+'&strtype='+item.orderinfo.strtype
            })
          }
         else if (item.ordertype == 12) {
            wx.navigateTo({
              url: '/xc_lshop/savemoney/recharge/index?key=' + item.orderinfo.keyval,
            })
          } else if (item.ordertype == 14) {
            wx.navigateTo({
              url: '/xc_lshop/savemoney/recharge/ht/index',
            })
          } else if (item.ordertype == 16) {
        
            wx.navigateTo({
              url: '/xc_lshop/savemoney/recharge/yiqida/infor?id='+item.orderinfo.plateid,
            })
          }else {
            actcart.buyagain(item.orderinfo)
            wx.redirectTo({
              url: '../cart/index',
            })
          }
          //cart.buyagain
          break;
        }
        case "exagain": {

          wx.navigateTo({
            url: '/xc_lshop/integralmall/pro/infor?id=' + item.orderinfo[0].proid,
          })
          // actcart.buyagain(item.orderinfo)
          // wx.redirectTo({
          //   url: '../cart/index',
          // })
          // //cart.buyagain
          break;
        }
        case "payoldorder": {
          this.opload(true, "支付中...")
          actbill.payoldorder(item.id).then(item => {
            if (item["op"] == "paysuccess") {
              that.onChangetabs({
                detail: {
                  name: "1"
                }
              }, true)
            }
            this.opload(false)
          })
          break;
        }
        case "closedorder": {
          wx.showModal({
            title: '确认关闭订单',
            content: "确认关闭订单",
            success(res) {
              if (res.confirm) {
                that.opload(true, "关闭订单中")
                actbill.closedorder(item.id).then(item => {
                  if (item["status"] == 1) {
                    that.opload(false)
                    // that.getpagelist(that, 1)
                    that.triggerEvent('opback', op)
                    wx.showToast({
                      title: "操作成功"
                    })
                  } else {
                    wx.showToast({
                      title: "操作失败"
                    })
                  }

                })
              } else if (res.cancel) {
                console.log('用户点击取消')
              }
            }
          })
          break;
        }
        case "finishbill": {
          var that = this;
          // that.triggerEvent('opback', op)
          // return;
          wx.showModal({
            title: '确认收货',
            content: "我确认，已收到货",
            success(res) {
              if (res.confirm) {
                actbill.finishbill(item.id).then(item => {
                  if (item["status"] == 1) {
                    that.setData({
                      'xcmodel.status': 9
                    })
                    that.triggerEvent('opback', op)
                    // that.onChangetabs({ detail: {name:"9"} }, true)
                    // that.opload(true)
                  } else {
                    wx.showToast({
                      title: "操作失败"
                    })
                  }

                })
              } else if (res.cancel) {
                console.log('用户点击取消')
              }
            }
          })
          break;
        }
        case "applyrefund": {
          var Comapplyrefund = this.selectComponent("#applyrefund");
          Comapplyrefund.showmodel(item.ordernum, 'order',item.status)
          break;
        }
        case "comment": {
          var Comordercomment = this.selectComponent("#ordercomment");
          Comordercomment.showmodel(item)
          break;
        }
      }
    },
  }
})